package com.echat.companydata.util;

import com.echat.commons.util.context.annotation.EchatConfigurable;
import com.echat.commons.util.redis.EchatRedis;
import com.echat.commons.util.redis.RedisPool;
import com.echat.commons.util.redis.constant.RedisNameEnum;
import com.echat.companydata.tool.ChatRedisKeys;
import com.echat.companydata.tool.RedisKey;

import java.util.Map;
import java.util.Set;

/**
 * Created by chenmohan on 2018/09/26
 *
 * @description
 */
@EchatConfigurable
public class CompanyDataRedisUtil {

    @RedisPool(name = RedisNameEnum.CHAT)
    private static EchatRedis redis;

    public static Long getCompanyVisitorOnLineNumber(Long companyId) {
        Long onlineNum = redis.hlen(RedisKey.companyVisitorMapKey(companyId));
        return onlineNum;
    }

    /**
     * 获取指定公总共聊天数量
     *
     * @param companyId
     * @return
     */
    public static long getCompanyTotalChatNumber(Long companyId) {
        Long chatNum = redis.hlen(RedisKey.companyChatMapKey(companyId));
        return chatNum;
    }

    public static Map getStaffStatusMap(Long companyId) {
        //1个公司的staff数量是比较少的,这里用了getAll
        Map<String, String> staffStatusMap = redis.hgetAll(RedisKey.staffStatusKey(companyId));
        return staffStatusMap;
    }

    public static Map getComanyRawDataMap(String dailyDataKey){
        Map<String, String> companyRawDataMap = redis.hgetAll(dailyDataKey);
        return companyRawDataMap;
    }

    public static Set getStaffIdSet(Long companyId){
        Set<String> staffIdSet = redis.hkeys(ChatRedisKeys.getChatProfileStaffInfoKey(companyId));
        return staffIdSet;
    }

    public static String getStaffInfo(Long companyId,String staffId){
        String staffInfoJsonString = redis.hget(ChatRedisKeys.getChatProfileStaffInfoKey(companyId), staffId);
        return staffInfoJsonString;
    }

    public static String getDepartmentInfo(Long companyId , Long departmentId){
        String departmentJsonString = redis.hget(ChatRedisKeys.getDepartmentMap(companyId), String.valueOf(departmentId));
        return departmentJsonString;
    }
}
